package domain.facade;
import dao.impl.*;
import domain.ApplicationContext;
import domain.facade.BoardService;
import domain.facade.FileService;
import domain.facade.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

/**
 * Created by IntelliJ IDEA.
 * User: winstars
 * Date: 2007-3-1
 * Time: 17:56:36
 * To change this template use File | Settings | File Templates.
 */
public class InitServlet extends HttpServlet {

    @Override
    public void init() throws ServletException {
        super.init();
        String DriverName="com.mysql.jdbc.Driver";
        String User="root";
        String Password="root";
        String DBName="Contest";
        String ConnURL="jdbc:mysql://127.0.0.1:3306/"+DBName;
        Integer MaxConnection=50;

        String TempLocation="C:\\TEMP";
        String SaveLocation="C:\\UPLOADED\\";

        System.out.println();
        System.out.println("/************ Start Configuration Of The System ****************/");
        
        System.out.println("===========Setting Up The Database and the Pool=======================");
        ConnectionPool connpl=new ConnectionPool(DriverName,User,Password,ConnURL,MaxConnection);
        
        System.out.println("===========Generating Services=======================");
        System.out.println("+++++++++++CREATING FileService+++++++++++");
        FileService fileService=new FileService();
        System.out.println("+++++++++++CREATING UserService+++++++++++");
        UserService userService=new UserService();
        System.out.println("+++++++++++CREATING BoardService+++++++++++");
        BoardService boardService=new BoardService();
        System.out.println("+++++++++++CREATING NewsService++++++++++++");
        NewsService newsService = new NewsService();
        
        System.out.println();
        System.out.println("===========Generating DAOs=======================");
        System.out.println("+++++++++++CREATING UsersDAO+++++++++++");
        UsersDaoImpl usersDao=new UsersDaoImpl();
        System.out.println("+++++++++++CREATING TypesDAO+++++++++++");
        TypesDaoImpl typesDao=new TypesDaoImpl();
        System.out.println("+++++++++++CREATING TopicsDao+++++++++++");
        TopicsDaoImpl topicsDao=new TopicsDaoImpl();
        System.out.println("+++++++++++CREATING ReplysDao+++++++++++");
        ReplysDaoImpl replysDao=new ReplysDaoImpl();
        System.out.println("+++++++++++CREATING FilesDao+++++++++++");
        FilesDaoImpl filesDao=new FilesDaoImpl();
        System.out.println("+++++++++++CREATING User_InfoDao+++++++++++");
        User_InfoDaoImpl user_InfoDao=new User_InfoDaoImpl();
        System.out.println("+++++++++++CREATING NewsDao");
        NewsDaoImpl newsDao = new NewsDaoImpl();
        
        System.out.println();
        System.out.println("===========Configuring DAOs===========");
        System.out.println("***********Setting UsersDAO***********");
        usersDao.setPool(connpl);
        usersDao.setTypesDao(typesDao);
        usersDao.setFilesDao(filesDao);
        usersDao.setReplysDao(replysDao);
        usersDao.setTopicsDao(topicsDao);
        System.out.println("***********Setting FilesDAO***********");
        filesDao.setPool(connpl);
        filesDao.setUsersDao(usersDao);
        System.out.println("***********Setting TypesDAO***********");
        typesDao.setPool(connpl);
        System.out.println("***********Setting TopicsDAO***********");
        topicsDao.setPool(connpl);
        topicsDao.setUsersDao(usersDao);
        topicsDao.setReplysDao(replysDao);
        System.out.println("***********Setting ReplysDAO***********");
        replysDao.setPool(connpl);
        replysDao.setUsersDao(usersDao);
        System.out.println("***********Setting NewsDao*************");
        newsDao.setPool(connpl);
        
        System.out.println();
        System.out.println("===========Configuring Services===========");
        System.out.println("***********Setting FileService***********");
        fileService.setFilesDao(filesDao);
        fileService.setTempLocation(TempLocation);
        fileService.setSaveLocation(SaveLocation);
        System.out.println("***********Setting BoardService***********");
        boardService.setReplysDao(replysDao);
        boardService.setTopicsDao(topicsDao);
        System.out.println("***********Setting UserService***********");
        userService.setUsersDao(usersDao);
        System.out.println("***********Setting NewsService***********");
        newsService.setNewsDao(newsDao);

        
        ApplicationContext.set("FileService",fileService);
        ApplicationContext.set("UserService",userService);
        ApplicationContext.set("BoardService",boardService);
        ApplicationContext.set("NewsService", newsService);
    }
}
